#!/usr/bin/python3
# -- coding: utf-8 --
# @Time : 2023/05/08 10:23
# -------------------------------
# cron "0 0 17 * * *" script-path=xxx.py,tag=匹配cron用
# const $ = new Env('双色球');
import requests
import random
import os
import json
# 企业微信机器人Webhook地址
wecom_webhook = "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=c4ed66c7-ea68-4b51-be3f-8319beb4504d"
# 企业微信推送函数
def Push(contents):
    headers = {'Content-Type': 'application/json'}
    data = {
        "msgtype": "text",
        "text": {
            "content": "双色球5注\n" + contents
        }
    }
    resp = requests.post(wecom_webhook, headers=headers, data=json.dumps(data))
    if resp.status_code == 200:
        print('企业微信机器人推送成功')
    else:
        print(f'企业微信机器人推送失败，状态码：{resp.status_code}')
headers ={
    'Content-Type': 'application/json',
    'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 15_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148'
}
data ={
    "limit":200,
    "page":1,
    "params":{}
}
resp = requests.post('https://ms.zhcw.com/proxy/lottery-chart-center/history/SSQ',headers=headers,data=json.dumps(data))
data = json.loads(resp.text)['datas']
# print(data)
redbulllist =[]
bruebulllist =[]
for i in range(len(data)):
    issue = data[i]['issue']
    redbull = data[i]['winningFrontNum'].split(' ')
    bruebull = data[i]['winningBackNum']
    bruebulllist.append(bruebull)
    redbulllist.append(redbull)
#定位函数
def find_all_index(lst, target):
    indices = []
    for i, value in enumerate(lst):
        if value == target:
            indices.append(i)
    return indices
print('为你生成2注双色球号码如下')
msg = []
for qul in range(5):
    # 统计每红球号码的出现次数
    count_red = [0] * 33
    for bull in redbulllist:
        for num in bull:
            count_red[int(num)-1] += 1
    #去出现次数最少的几个
    min_ten = sorted(count_red)[:33]
    # print(min_ten)
    #定位所在位置数字
    allred =[]
    for a in range(10):
        red = find_all_index(count_red,min_ten[a])
        for b in range(len(red)):
            allred.append(red[b]+1)
    finallist = sorted(list(set(allred)))
    # print(finallist)
    # 统计每篮球号码的出现次数
    count_brue = [0] * 16
    for bull in bruebulllist:
        count_brue[int(bull)-1] += 1
    # print(count_brue)
    min_3 = sorted(count_brue)[:9]
    # print(min_3)
    #定位所在位置数字
    allbrue =[]
    for a in range(5):
        brue = find_all_index(count_brue,min_3[a])
        for b in range(len(brue)):
            allbrue.append(brue[b]+1)
    finallist2 = sorted(list(set(allbrue)))
    # print(finallist2)
    # 修正这一行：添加了缺失的括号
    msg.append(str(sorted(random.sample(finallist,6))) + ' - ' + str(sorted(random.sample(finallist2,1))))
massage = str(msg).replace('\', \'','\n').replace('[','').replace(']','').replace('\'','')
print(massage)
Push(contents=massage)